<?php
//============================================================+
// File name   : example_001.php
// Begin       : 2008-03-04
// Last Update : 2010-08-14
//
// Description : Example 001 for TCPDF class
//               Default Header and Footer
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com s.r.l.
//               Via Della Pace, 11
//               09044 Quartucciu (CA)
//               ITALY
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Default Header and Footer
 * @author Nicola Asuni
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
 * @link http://tcpdf.org
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
 * @since 2008-03-04
 */

App::import('Vendor','tcpdf/config/lang/eng');
App::import('Vendor','tcpdf'); 

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Sylwester Kowal (21w.pl)');
$pdf->SetTitle('Cleaning Service');
$pdf->SetSubject(__("Wykaz zlecen za wybrany okres wg daty realizacji",true));
$pdf->SetKeywords('cleaning, service');

// set default header data
$pdf->SetHeaderData(false, null, __("Wykaz zlecen za wybrany okres wg daty realizacji",true), 'from date '.$session->read('Reports.date_from'). ' to '. $session->read('Reports.date_to'));

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
//$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusanscondensed', '', 12, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage('','LETTER');

// Set some content to print
//$html = <<<EOD
//<h1>Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0000;color:black;">&nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a>!</h1>
//<i>This is the first example of TCPDF library.</i>
//<p>This text is printed using the <i>writeHTMLCell()</i> method but you can also use: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p>
//<p>Please check the source code documentation and other examples for further information.</p>
//<p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a></p>
//EOD;
// create some HTML content



$html = '
		<div class="orders index">
			<h1>'.__("Orders",true).'</h1>
			<table cellpadding="0" cellspacing="0" border="1">
			<tr>
					<th width="10%"  align="center">'.__("Day",true).'</th>
					<th width="90%" align="center">'.__("Employees/Orders",true).'</th>
			</tr>';

			$i = 0;
			foreach ($orders as $date => $employees){
				$class = null;
				if ($i++ % 2 == 0) {
					$class = ' style="background-color:#eeeeee;"';
				}
$class__ = "";	
$rozdziel_employees = (count($employees) == 1)?"":"class=\"rozdziel_employee\"";			
$html .= '
			<tr'.$class.'>
				<td width="10%" valign="top" align="center">
					<table cellpadding="5" cellspacing="0" border="0"><tr><td>
					'.$time->format("M d D Y",$date).'
					</td></tr></table>
				</td>
				<td class="actions" width="90%" valign="top">

					<table cellpadding="0" cellspacing="0" border="1" bordercolor="#EEEEEE">';

						$j = 0;						
						foreach ($employees as $employee_id => $employee){
							$class_ = null;
							if ($j++ % 2 == 0) {
								$class_ = ' ';
							}
							if($j >= 2){
								$class__ = $rozdziel_employees;
							}
$class____ = "";
$rozdziel_orders = (count($employee['orders']) == 1)?"":"class=\"rozdziel_orderse\"";							
$html .= '
						<tr'.$class_.'>
							<td width="30%" style="padding: 5px;" '.$class__.' valign="top">
								<table cellpadding="5" cellspacing="0" border="0"><tr><td>
								'.$employee['emplo']['name'].' '.$employee['emplo']['surname'].'<br/>
								'.$employee['emplo']['phone1'].'<br/>
								'.$typeOfWorks[$employee['emplo']['type_of_work_id']].'
								'.((!empty($employee['emplo']['type_of_work_2_id'])) ? $typeOfWorks[$employee['emplo']['type_of_work_2_id']]: "").'
								'.((!empty($employee['emplo']['type_of_work_3_id'])) ? $typeOfWorks[$employee['emplo']['type_of_work_3_id']]: "").'
								</td></tr></table>
							</td>
							<td width="70%" '.$class__.' valign="top">			
						
								<table cellpadding="5" cellspacing="0" border="1" bordercolor="#aaaaaa">';

									$k = 0;
									foreach ($employee['orders'] as $orders_id => $order){
										$class___ = null;
										if ($k++ % 2 == 0) {
											$class___ = ' style=""';
										}
										if($k >= 2){
											$class____ = $rozdziel_orders;
										}										
$html .= '
									<tr'.$class___.'>
										<td width="40%" '.$class____.' valign="top">
											'.$order['TypesOfSpaces']['name'].' '.$order['TypeOfService']['name'].'<br/>
											'.$order['Order']['estimated_execution_time'].' '.__("hours",	true).'<br/>
											'.$order['Order']['value_of_the_order'].' '.__("USD",	true).'<br/>
										</td>
										<td width="60%" '.$class____.' valign="top">
											'.$order['Customer']['name'].' '.$order['Customer']['surname'].'<br/>
											'.$order['Customer']['address1'].' '.$order['Customer']['address2'].'<br/>
											'.$order['Customer']['address3'].' '.$order['Customer']['address4'].'<br/>
											'.__("Phone",true).' '.$order['Customer']['phone1'].'
										</td>
									</tr>';
									};
$html .= '						</table>
							
							</td>
						</tr>';
						};
$html .= '			</table>
				</td>
			</tr>';
			};
$html .= '	</table>
		</div>';



// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');

// Print text using writeHTMLCell()
//$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$data = date('YmdHis');
$pdf->Output("cleaning_service_{$data}.pdf", 'I');
//============================================================+
// END OF FILE
//============================================================+